#ifndef TYPEDEF_H
#define TYPEDEF_H

#include <string>

#pragma pack(push, 1)
#define PACKED
// #define PACKED __attribute__((packed))

typedef unsigned long  COLORREF;
typedef char           TCHAR;
typedef unsigned long  DWORD;
typedef int            BOOL;
typedef unsigned char  BYTE;
typedef unsigned short WORD;
typedef float          FLOAT;

#define VOID void
typedef char  CHAR;
typedef short SHORT;
typedef long  LONG;

#define _T

#ifndef FALSE
#define FALSE 0
#endif

#ifndef TRUE
#define TRUE 1
#endif

#define INIT_STRUCT_ZERO(obj) memset(&(obj), 0, sizeof(obj))
#define CONSTRUCTOR_ZERO(__STRUCT_NAME__) __STRUCT_NAME__() { INIT_STRUCT_ZERO(*this); }

typedef struct tagRECT
{
    LONG left;
    LONG top;
    LONG right;
    LONG bottom;
} RECT, *PRECT;

typedef struct tagRGBQUAD
{
    BYTE rgbBlue;
    BYTE rgbGreen;
    BYTE rgbRed;
    BYTE rgbReserved;
} RGBQUAD;

/* Logical Font */
#define LF_FACESIZE 32
typedef struct PACKED tagLOGFONTA
{
    LONG lfHeight;
    LONG lfWidth;
    LONG lfEscapement;
    LONG lfOrientation;
    LONG lfWeight;
    BYTE lfItalic;
    BYTE lfUnderline;
    BYTE lfStrikeOut;
    BYTE lfCharSet;
    BYTE lfOutPrecision;
    BYTE lfClipPrecision;
    BYTE lfQuality;
    BYTE lfPitchAndFamily;
    CHAR lfFaceName[LF_FACESIZE];
    CONSTRUCTOR_ZERO(tagLOGFONTA)
} LOGFONT;

#define DECLARE_HANDLE(name) \
    struct name##__          \
    {                        \
        int unused;          \
    };                       \
    typedef struct name##__* name
DECLARE_HANDLE(HRSRC);

typedef struct tagPOINT
{
    LONG x;
    LONG y;
} POINT;

typedef struct PACKED tagBITMAPINFOHEADER
{
    DWORD biSize;
    LONG  biWidth;
    LONG  biHeight;
    WORD  biPlanes;
    WORD  biBitCount;
    DWORD biCompression;
    DWORD biSizeImage;
    LONG  biXPelsPerMeter;
    LONG  biYPelsPerMeter;
    DWORD biClrUsed;
    DWORD biClrImportant;
    CONSTRUCTOR_ZERO(tagBITMAPINFOHEADER)
} BITMAPINFOHEADER;

typedef struct PACKED tagBITMAPFILEHEADER
{
    WORD  bfType;
    DWORD bfSize;
    WORD  bfReserved1;
    WORD  bfReserved2;
    DWORD bfOffBits;
    CONSTRUCTOR_ZERO(tagBITMAPFILEHEADER)
} BITMAPFILEHEADER;

typedef struct PACKED tagBITMAPCOREHEADER
{
    DWORD bcSize; /* used to get to color table */
    WORD  bcWidth;
    WORD  bcHeight;
    WORD  bcPlanes;
    WORD  bcBitCount;
    CONSTRUCTOR_ZERO(tagBITMAPCOREHEADER)
} BITMAPCOREHEADER;

typedef struct tagRGBTRIPLE
{
    BYTE rgbtBlue;
    BYTE rgbtGreen;
    BYTE rgbtRed;
} RGBTRIPLE;

#define BI_RGB       0L
#define BI_RLE8      1L
#define BI_RLE4      2L
#define BI_BITFIELDS 3L
#define BI_JPEG      4L
#define BI_PNG       5L

#define MAKEWORD(a, b) ((WORD)(((BYTE)(a)) | ((WORD)((BYTE)(b))) << 8))
#define MAKELONG(a, b) ((LONG)(((WORD)(a)) | ((DWORD)((WORD)(b))) << 16))
#define LOWORD(l)      ((WORD)(l))
#define HIWORD(l)      ((WORD)(((DWORD)(l) >> 16) & 0xFFFF))
#define LOBYTE(w)      ((BYTE)(w))
#define HIBYTE(w)      ((BYTE)(((WORD)(w) >> 8) & 0xFF))

#define RGB(r, g, b)   ((COLORREF)(((BYTE)(r) | ((WORD)((BYTE)(g)) << 8)) | (((DWORD)(BYTE)(b)) << 16)))
#define GetRValue(rgb) (LOBYTE(rgb))
#define GetGValue(rgb) (LOBYTE(((WORD)(rgb)) >> 8))
#define GetBValue(rgb) (LOBYTE((rgb) >> 16))

#pragma pack(pop)

#endif // TYPEDEF_H
